package com.jysz.webcore.utils;

import java.lang.reflect.Field;

import org.apache.commons.beanutils.PropertyUtils;

/**
 * @author <a href="mailto:javaengine@outlook.com">Kaca Rich</a>
 *
 */
public class SshBeanUtils {
	
	public static <T> T copyProperties(T src, T dest, String[] properties) {
		for (String property : properties) {
			try {
				Object value = PropertyUtils.getProperty(src, property);
				PropertyUtils.setProperty(dest, property, value);
			} catch (Exception e) {
			}
		}
		return dest;
	}
	
	public static <T> T copyProperties(T src, T dest) {
		for (Field property : dest.getClass().getDeclaredFields()) {
			try {
				Object value = PropertyUtils.getProperty(src, property.getName());
				PropertyUtils.setProperty(dest, property.getName(), value);
			} catch (Exception e) {
			}
		}
		return dest;
	}
	
}
